#ifndef _ANIMATION_H_
#define _ANIMATION_H_

#include "BuzzGlobals.h"
#include "Image.h"

class Animation : public Image
{
public:
	Animation(const char* filename, int noFrames, int frameTime, ColourKey key=ColourKey());

    virtual ~Animation();

    /**
     * Draws the animation at the specified coordinates
     * \see Image::draw
     */
    virtual void draw(int x, int y, bool flipped = false);

    /// Returns which frame the animation is currently on (from 0 to frames-1)
    int getFrameNumber();

    Image* getCurrentFrame();

    Image* getFrame(int i){ return frames[i]; }

    int getNoFrames(){ return noFrames; }

    /// Starts/Restarts the animation from frame 0
    void start();

    /// Overridden height method to return the height of a single frame
    virtual int getHeight() { return height; }

	virtual int getWidth(){ return width; }

    /// Calculates how many times the animation has looped
    int getPlayCount();

    bool isLooping(){ return looping; }

    void setLooping(bool looping){ this->looping = looping; }

	virtual void setReferencePoint(int x, int y);

	virtual byte** getCollisionMap(){ return getCurrentFrame()->getCollisionMap(); }
	virtual bool collisionAt(int x, int y, bool flipped=false){ return getCurrentFrame()->collisionAt(x,y,flipped); }

private:
    Image** frames;

    /// The number of frames in the animation
    int noFrames;

    /// The number of milliseconds each frame lasts
    int frameTime;

    /// SDL Tick time for when the animation started
    Uint32 startTime;

    /// Height of the whole animation strip image
    int imageHeight;

    int currentFrameNumber;

    bool looping;
};

#endif
